﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace DA
{
   public class nhapbangdiemmonhoc_DA
    {
        DataLINQHocSinhDataContext ql = new DataLINQHocSinhDataContext();
        public object layallhs()
        {
            return ql.HOCSINHs.ToList();
        }
        public object layallmh()
        {
            return ql.MONHOCs.ToList();
        }
        public object layallml()
        {
            return ql.LOPs.ToList();
        }
        public object layallbd()
        {
            return ql.BANGDIEMs.ToList();
        }
        public bool kiemtradulieutrung(BANGDIEM bdmh)
        {
            var query = from p in ql.BANGDIEMs
                        where p.MAHS == bdmh.MAHS && p.MAMH == bdmh.MAMH && p.MALOP==bdmh.MALOP && p.MAHK==bdmh.MAHK
                        select p;
            if (query.Count() != 0)
            {
                return true;
            }
            return false;
        }
        public void them(BANGDIEM bdmh)
        {
            BANGDIEM a = new BANGDIEM();
            a.MAHS = bdmh.MAHS;
            a.MAMH = bdmh.MAMH;
            a.D15 = bdmh.D15;
            a.D1T = bdmh.D1T;
            a.DTB = bdmh.DTB;
            a.MALOP = bdmh.MALOP;
            a.MAHK = bdmh.MAHK;
            ql.BANGDIEMs.InsertOnSubmit(a);
            ql.SubmitChanges();
        }
        public void xoa(BANGDIEM bdmh)
        {
            var query = from p in ql.BANGDIEMs
                        where p.MAHS == bdmh.MAHS && p.MAMH == bdmh.MAMH && p.MALOP==bdmh.MALOP && p.MAHK==bdmh.MAHK
                        select p;
            ql.BANGDIEMs.DeleteAllOnSubmit(query);
            ql.SubmitChanges();

        }
        public void sua(BANGDIEM bdmh)
        {
            BANGDIEM bd = ql.BANGDIEMs.Single(p => p.MAHS == bdmh.MAHS && p.MAMH == bdmh.MAMH && p.MALOP==bdmh.MALOP&&p.MAHK==bdmh.MAHK);
            //bd.MAHS = bdmh.MAHS;
            //bd.MAMH = bdmh.MAMH;
            //bd.MONHOC = bdmh.MONHOC;
            //bd.MALOP = bdmh.MALOP;
            //bd.MAHK = bdmh.MAHK;
            //bd.LOP = bdmh.LOP;
            //bd.HOCSINH = bdmh.HOCSINH;
            bd.D15 = bdmh.D15;
            bd.D1T = bdmh.D1T;
            bd.DTB = bdmh.DTB;
            ql.SubmitChanges();
        }
        public object loadcb()
        {
            return ql.HOCSINHs.ToList();
        }
    }
}
